/*


 */

package jas.rpc.client;

import java.io.IOException;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

/**
 * Translates stub objects to their corresponding <code>RemoteObject</code> objects.
 */
public class RpcClientObjectOutputStream extends ObjectOutputStream {
    
    public RpcClientObjectOutputStream(OutputStream output) throws IOException {
        super(output);
        enableReplaceObject(true);
    }
    
    @Override
    protected final Object replaceObject(Object obj) throws IOException {
        if (obj instanceof RemoteStub) {
            RemoteStub stub = (RemoteStub) obj;
            return stub.getRemoteObject();
        }
        return obj;
    }
    
}
